package com.jia.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jia.entity.SysRole;
import com.jia.entity.SysUserRole;
import com.jia.mapper.SysUserRoleMapper;
import com.jia.service.SysRoleService;
import com.jia.service.SysUserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 杜佳佳
 * @since 2021-05-23
 */
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements SysUserRoleService {

    @Autowired
    private SysRoleService sysRoleService;

    @Override
    public List<SysRole> getRoleListByUserId(String userId) {
        QueryWrapper<SysUserRole> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);

        List<SysUserRole> sysUserRoles = baseMapper.selectList(wrapper);
        List<SysRole> roleList = new ArrayList<>();
        if (sysUserRoles.size() > 0){
            sysUserRoles.forEach(item->{
                String roleId = item.getRoleId();
                SysRole sysRole = sysRoleService.getById(roleId);
                roleList.add(sysRole);
            });
        }

        return roleList;
    }
}
